package com.mc.service;

import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

@Setter
@Getter
@ToString
public class BaseApiService {


    private HttpServletRequest request;


    public JSONObject getRequestJson() throws IOException {


        BufferedReader streamReader = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
        StringBuilder responseStrBuilder = new StringBuilder();
        String inputStr;
        while ((inputStr = streamReader.readLine()) != null) {
            responseStrBuilder.append(inputStr);
        }

        return JSONObject.parseObject(responseStrBuilder.toString());
    }


    public String getPara(String name) {
        String result = request.getParameter(name);
        return result;
    }


}
